package com.chenwang.measure.model.bean;

import com.chenwang.measure.utils.MyCrashHandler;
import com.chenwang.measure.utils.MyLogger;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @松 on 2019/7/29 13:05
 * 定位信息
 */
public class LocationBean {


    private boolean state;//设备是否连接
    private Double lat;//纬度
    private Double lon; //经度
    private Double hight; //高度
    private String satelliteTotal ="0";//卫星总数
    private String staellite ="0";//参与解算卫星数；offset
    private float latOffset=0;//纬度差
    private float lonOffset=0;//经度差
    private float hightOffset =0;//高度差
    private int sol=0;//解状态
    private int pos = 0;//定位类型
    private int cosr;//cors
    private boolean isSource ;//源数据
    private boolean is925;// 解析925标识
    private String ok;     //保存解析到的指令发送 返回的状态 ok
    private boolean isOkMsg; //是否解析指令发送返回指令
    private int lastCors = 7;//上一次 Cors值
    private static LocationBean instance;




    public static LocationBean getInstance() {
        if (instance == null) {
            synchronized (LocationBean.class) {
                if (instance == null) {
                    instance = new LocationBean();
                }
            }
        }
        return instance;
    }



    public boolean isOkMsg() {
        return isOkMsg;
    }

    public void setOkMsg(boolean okMsg) {
        isOkMsg = okMsg;
    }

    public String getOk() {
        return ok;
    }

    public void setOk(String ok) {
        this.ok = ok;
    }

    public boolean isIs925() {
        return is925;
    }

    public void setIs925(boolean is925) {
        this.is925 = is925;
    }

    public boolean isSource() {
        return isSource;
    }
    public boolean isState() {
        return state;
    }

    public void setState(boolean state) {
        this.state = state;
    }

    public void setSource(boolean source) {
        isSource = source;
    }

    public List<String> getSource() {
        return source;
    }

    public void setSource(List<String> source) {
        this.source = source;
    }

    private List<String> source = new ArrayList<>();

    public int getCosr() {
        return cosr;
    }

    public void setCosr(int cosr) {
        this.cosr = cosr;
    }





    /**
     * 保证源数据不可有重复
     * @param s 源数据
     */
    public void setSource(String s){
        if (source.size()>0){
            boolean is = false;
            for (int i=0; i<source.size();i++){
                if (source.get(i).equals(s)){
                    is =true;
                    break;
                }

            }
            if (!is){
                source.add(s);
            }

        }else {
            source.add(s);
        }

    }

    public int getLastCors() {
        return lastCors;
    }

    public void setLastCors(int lastCors) {
        this.lastCors = lastCors;
    }

    //获取水平精度 返回经纬度偏差最大的值
    public double getHorizontal(){
        if ((latOffset !=0)&&(lonOffset!=0)){
            if (latOffset > lonOffset){
                return latOffset;
            }else {
                return lonOffset;
            }
        }else {
         return 0;
        }
    }

    //清空
    public void clear(){
       // state=false;
        pos =0;
        sol =-1;

        lat =0.0;//纬度
        lon = 0.0; //经度
        hight =0.0; //高度
        satelliteTotal ="0";//卫星总数
     //   staellite ="0";//参与解算卫星数；offset
         latOffset=0;//纬度差
         lonOffset=0;//经度差
         hightOffset =0;//高度差
    }

    private String Messgae;

    public static void setInstance(LocationBean instance) {
        LocationBean.instance = instance;
    }

    public String getMessgae() {
        return Messgae;
    }

    public void setMessgae(String messgae) {
        Messgae += messgae;
    }

    public Double getLat() {
        if (lat !=null){
            return lat;
        }else {
            return 0.0;
        }

    }

    public void setLat(Double lat) {
        this.lat = lat;
    }

    public Double getLon() {
        if (lon !=null){
            return lon;
        }else {
            return 0.0;
        }
    }

    public void setLon(Double lon) {
        this.lon = lon;
    }

    public Double getHight() {
        if (hight !=null){
            return hight;
        }else {
            return 0.0;
        }
    }

    //高度精度  vertrcal
    public double getVertrcal() {

        try {
            if (hightOffset !=0){
                BigDecimal b = new BigDecimal(String.valueOf(hightOffset));
                return b.doubleValue();
            }
        }catch (NumberFormatException e){
            //！！！！
            MyCrashHandler.newInstance().saveCrashInfoToFile(e);
            MyLogger.e(e.getMessage());
        }
        return 0;
    }

    public void setHight(Double hight) {
        this.hight = hight;
    }

    public String getSatelliteTotal() {
        return satelliteTotal;
    }

    public void setSatelliteTotal(String satelliteTotal) {
        this.satelliteTotal = satelliteTotal;
    }

    public String getStaellite() {
        return staellite;
    }

    public void setStaellite(String staellite) {
        this.staellite = staellite;
    }

    public float getLatOffset() {
        return latOffset;
    }

    public void setLatOffset(float latOffset) {
        this.latOffset = latOffset;
    }

    public float getLonOffset() {
        return lonOffset;
    }

    public void setLonOffset(float lonOffset) {
        this.lonOffset = lonOffset;
    }

    public float getHightOffset() {
        return hightOffset;
    }

    public void setHightOffset(float hightOffset) {
        this.hightOffset = hightOffset;
    }

    public int getSol() {
        return sol;
    }

    public void setSol(int sol) {
        this.sol = sol;
    }

    public int getPos() {
        return pos;
    }

    public void setPos(int pos) {
        this.pos = pos;
    }
}
